import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 页面内容 左侧树
export function getPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
  }
  return request({
    url: '/getAdminPage',
    method: 'post',
    data: data
  })
}

// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    deptId: queryParams.deptId,  //所属部门 id
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords
  }
  return request({
    url: '/getAdminList',
    method: 'post',
    data: data
  })
}

// 新增
export function addData(val) {
  const data = {
    projectContent:{
      ascriptionId: store.state.userInfo.ascriptionId, //机构 id
      adminName: val.adminName, //用户名称
      userName: val.userName, //登录账号
      password: val.password, //登录密码
      deptId: val.deptId, //所属部门 id
      deptName: val.deptName, //所属部门
      roleId: val.roleId, //用户角色 id
      roleName: val.roleName, //用户角色
      jurisdiction: val.jurisdiction, //权限文本列表
      menuIds: val.menuIds, //权限列表
      phone: val.phone, //联系电话
    }
  }
  return request({
    url: '/addAdmin',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getAdminData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      theid: val.theid,
      adminName: val.adminName,
      userName: val.userName,
      password: val.password,
      deptId: val.deptId,
      deptName: val.deptName,
      roleId: val.roleId,
      roleName: val.roleName,
      jurisdiction: val.jurisdiction,
      menuIds: val.menuIds,
      phone: val.phone,
    }
  }
  return request({
    url: '/updateAdmin',
    method: 'post',
    data: data
  })
}


// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delAdmin',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleAdmin',
    method: 'post',
    data: data
  })
}

// 下拉框
export function getSelect() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getAdminComboBox',
    method: 'post',
    data: data
  })
}

// 状态
export function changeEnable(theid,enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableAdmin',
    method: 'post',
    data: data
  })
}

// 获取登录日志 页面内容
export function getLogPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    userId: queryParams.userId,  //用户 id
    startTime: queryParams.startTime,  //开始时间
    endTime: queryParams.endTime,  //结束时间
  }
  return request({
    url: '/getAdminLoginlogPage',
    method: 'post',
    data: data
  })
}

// 获取登录日志 数据列表
export function logListData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    userId: queryParams.userId,  //用户 id
    startTime: queryParams.startTime,  //开始时间
    endTime: queryParams.endTime,  //结束时间
  }
  return request({
    url: '/getAdminLoginlogList',
    method: 'post',
    data: data
  })
}

